package com.dingwei.superiordiary.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.MyLevelBean;
import com.dingwei.superiordiary.mvp.presenter.MyLevelPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.dingwei.superiordiary.utils.NumberUtil;
import com.dingwei.superiordiary.utils.SpanUtils;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.MathUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/10/27.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class MyLevelActivity extends BaseActivity implements Contract.MyLevelView {

    MyLevelPresenter myLevelPresenter = new MyLevelPresenter(this);

    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.tv_nick_name)
    TextView tvNickName;
    @Bind(R.id.tv_num_id)
    TextView tvNumId;
    @Bind(R.id.progressBarHorizontal)
    ProgressBar progressBarHorizontal;
    @Bind(R.id.tv_level)
    TextView tvLevel;
    @Bind(R.id.tv_progress)
    TextView tvProgress;
    @Bind(R.id.tv_level_progress)
    TextView tvLevelProgress;
    @Bind(R.id.Introduction)
    TextView Introduction;
    @Bind(R.id.no_net_btn)
    TextView noNetBtn;
    @Bind(R.id.no_net_layout)
    RelativeLayout noNetLayout;
    @Bind(R.id.data_layout)
    ScrollView dataLayout;
    @Bind(R.id.img_head)
    ImageView imgHead;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_my_level;
    }

    @Override
    protected void initData() {
        myLevelPresenter.initData();
    }

    @Override
    protected void initView() {

        tvTitle.setText("我的等级");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.no_net_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.no_net_btn:
                myLevelPresenter.initData();
                break;
        }
    }

    @Override
    public void setData(MyLevelBean bean) {

        Glide.with(BaseActivity.context)
                .load(bean.data.portrait)
                .apply(MyApplication.headOptions)
                .into(imgHead);
        tvNickName.setText(bean.data.nickname);
        tvNumId.setText(bean.data.id+"（数字ID）");
        tvLevel.setText("LV." + bean.data.level);
        tvLevelProgress.setText(bean.data.experience + "/" + bean.data.next_experience);
        tvProgress.setText(NumberUtil.getPercentValue(bean.data.next_ratio,0));
        progressBarHorizontal.setProgress((int) (100 * bean.data.next_ratio));


        Introduction.setText(new SpanUtils()
                .append("每日登录  ")
                .appendLine("+" + bean.data.condition.day_login_integral).setForegroundColor(getResources().getColor(R.color.red))

                .append("第一次签到  ")
                .appendLine("+" + bean.data.condition.sign_integral_number).setForegroundColor(getResources().getColor(R.color.red))

                .append("每次点赞一次  ")
                .append("+" + bean.data.condition.praise_integral_number).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日上限" + bean.data.condition.praise_day_limit + "次").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("每日发布一贴  ")
                .append("+" + bean.data.condition.activiry_integral_number).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日上限" + bean.data.condition.activiry_day_limit + "次").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("每日回复贴子  ")
                .append("+" + bean.data.condition.replay_activity_integral).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日上限" + bean.data.condition.replay_activity_day_limit + "次").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("帖子入选精选  ")
                .append("+" + bean.data.condition.essence_integral_number).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日无上限").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("被赞超过")
                .append("+" + bean.data.condition.praise_limit_num).setForegroundColor(getResources().getColor(R.color.red))
                .append("  每个帖子")
                .append("+" + bean.data.condition.praise_limit_activity_integral).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日无上限").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("被转超过")
                .append("+" + bean.data.condition.reprint_limit_number).setForegroundColor(getResources().getColor(R.color.red))
                .append("  每个帖子")
                .append("+" + bean.data.condition.reprint_limit_integral).setForegroundColor(getResources().getColor(R.color.red))
                .appendLine("  每日无上限").setForegroundColor(getResources().getColor(R.color.theme_color))

                .append("一次有效的举报")
                .append("(被举报确有违规行为)  +" + bean.data.condition.report_integral_number)
                .appendLine("  每日上限" + bean.data.condition.report_limit_number + "次").setForegroundColor(getResources().getColor(R.color.theme_color))

//                .append("发布违规内容被处理")
//                .append("  -" + bean.data.condition.irregularities)
//                .append("  情节严重者封号").setForegroundColor(getResources().getColor(R.color.theme_color))
                .create());
        showData("success");
    }

    @Override
    public void onFail() {
        showData("fail");
    }

    public void showData(String state) {
        if (state.equals("success")) {
            dataLayout.setVisibility(View.VISIBLE);
            noNetLayout.setVisibility(View.GONE);
        } else {
            dataLayout.setVisibility(View.GONE);
            noNetLayout.setVisibility(View.VISIBLE);
        }
    }
}
